namespace OWA.Activities
{
    using System;
    using System.Xml;
    using System.Reflection;
    using System.IO;
    using System.Xml.Schema;
    using System.Collections.Generic;

    class AssemblyResolver
        : XmlResolver
    {
        const string _resourceBaseName = "OWA.Activities.Schemas";

        public override Uri ResolveUri(Uri baseUri, string relativeUri)
        {
            return new Uri(relativeUri, UriKind.Relative);
        }

        public override System.Net.ICredentials Credentials
        {
            set {  }
        }

        public override object GetEntity(Uri absoluteUri, 
            string role, Type ofObjectToReturn)
        {
            XmlSchema schema = null;
            string resourceName = String.Concat(
                _resourceBaseName,
                ".",
                absoluteUri.ToString());
            Assembly assembly = Assembly.GetExecutingAssembly();
            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                schema = XmlSchema.Read(stream, null);
            }
            return schema;
        }
    }
}
